package com.hlkj.interceptor;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

/**
 * 这个类用来解决struts2和fck冲突造成无法上传图片或文件的问题，原
 * 因是struts在web.xml中配制的过滤器把fck的servlet请求转发了。
 * 用这个类替换掉web.xml中的struts过滤器类StrutsPrepareAndExecuteFilter就可以了
 * @author zhukui 
 */
public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1,
			FilterChain arg2) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) arg0;
		// 不过滤的url
		String url = request.getRequestURI();
		System.out.println("----------请求URL="+url);

		url = url.substring(url.lastIndexOf("/") + 1, url.length());

		if ("imageUp.jsp".equals(url)) {
			arg2.doFilter(arg0, arg1);//上传图片时请求不转发
		} else {
			super.doFilter(arg0, arg1, arg2);
		}
	}

}
